package com.hi.hiparty.manager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hi.hiparty.dao.UserDao;
import com.hi.hiparty.entity.User;

@Service
public class UserManager {
	
	private static final Log logger = LogFactory.getLog(UserManager.class);
	
	@Autowired
	private UserDao userDao;
	
	public int checkLoginName(String loginname) throws Exception{
		return userDao.checkLoginName(loginname);
	}
	
	public int addUser(String loginname,String password) throws Exception{
		return userDao.addUser(loginname, password);
	}
	
	public User checkLogin(String loginname,String password) throws Exception{
		return userDao.checkLogin(loginname, password);
	}
	
	public User getUser(int id){
		try {
			return userDao.getUser(id);
		} catch (Exception e) {
			logger.error("get User error.id:"+id,e);
			return null;
		}
	}
	
	public Integer updateUser(User user){
		try {
			return userDao.updateUser(user);
		} catch (Exception e) {
			logger.error("updateUser error.id"+user.getUserid(), e);
			return -1;
		}
	}
	
	public Integer updateUserNicknameAndGender(String userid, String nickname,
			String gender) throws Exception {
		return userDao.updateUserNicknameAndGender(userid, nickname, gender);
	}
	
	public boolean updateUserAvatar(String userid,String avatarUrl){
		try {
			return userDao.updateUserAvatar(userid,avatarUrl)>0;
		} catch (Exception e) {
			logger.error("updateUserAvatar error", e);
			return Boolean.FALSE;
		}
	}
}
